{% extends 'myadmin/public/base.html' %}

{% block title %}
<title>后台会员列表</title>
{% endblock %}


{% block header %}
    <div class="row">
        <div class="am-u-sm-12 am-u-md-12 am-u-lg-9">
            <div class="page-header-heading"><span class="am-icon-home page-header-heading-icon"></span>会员列表</div>
            <p class="page-header-description">Amaze UI </p>
        </div>
    </div>
{% endblock %}
 

{% block con %}
<div class="row-content am-cf">
    <div class="row">
        <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
            <div class="widget am-cf">
                <div class="widget-head am-cf">
                    <div class="widget-title  am-cf">会员列表</div>


                </div>
                <div class="widget-body  am-fr">

                    <div class="am-u-sm-12 am-u-md-6 am-u-lg-6">
                        <div class="am-form-group">
                            <div class="am-btn-toolbar">
                                <div class="am-btn-group am-btn-group-xs">
                                    <button type="button" class="am-btn am-btn-default am-btn-success"><span class="am-icon-plus"></span> 新增</button>
                                    <button type="button" class="am-btn am-btn-default am-btn-secondary"><span class="am-icon-save"></span> 保存</button>
                                    <button type="button" class="am-btn am-btn-default am-btn-warning"><span class="am-icon-archive"></span> 审核</button>
                                    <button type="button" class="am-btn am-btn-default am-btn-danger"><span class="am-icon-trash-o"></span> 删除</button>
                                </div>
                            </div>
                        </div>
                    </div>

                <form>
                    <div class="am-u-sm-12 am-u-md-6 am-u-lg-3">
                        <div class="am-form-group tpl-table-list-select">
                            <select name="type" data-am-selected="{btnSize: 'sm'}" style="display: none;">
                        
                              <option value="username" {% if request.GET.type == 'username' %} selected {% endif %} >姓名</option>
                              <option value="age" {% if request.GET.type == 'age' %} selected {% endif %} >年龄</option>
                              <option value="email" {% if request.GET.type == 'email' %} selected {% endif %} >邮箱</option>
                              <option value="phone" {% if request.GET.type == 'phone' %} selected {% endif %} >手机号</option>
                              <option value="sex" {% if request.GET.type == 'sex' %} selected {% endif %} >性别</option>
                            </select>
                        </div>
                    </div>
                    <div class="am-u-sm-12 am-u-md-12 am-u-lg-3">
                        <div class="am-input-group am-input-group-sm tpl-form-border-form cl-p">
                            <input type="text" name="keywords" class="am-form-field " value="{{ request.GET.keywords }}">
                            <span class="am-input-group-btn">
                            <button class="am-btn  am-btn-default am-btn-success tpl-table-list-field am-icon-search"></button>
                          </span>
                        </div>
                    </div>
                </form>


                    <div class="am-u-sm-12">
                        <table width="100%" class="am-table am-table-compact am-table-striped tpl-table-black ">
                            <thead>
                                <tr>
                                    <th>ID</th>
                                    <th>头像缩略图</th>
                                    <th>用户名</th>
                                    <th>邮箱</th>
                                    <th>手机号</th>
                                    <th>性别</th>                        
                                    <th>年龄</th>
                                    <th>状态</th>
                                    <th>注册时间</th>
                                    <th>操作</th>
                                </tr>
                            </thead>
                            <tbody>
                            {% for v in userlist %}
                                <tr>
                                    <td class="am-text-middle">{{ v.id }}</td>
                                    <td>
                                        <img src="{{ v.pic|default:'/static/pics/users.jpg' }}" class="tpl-table-line-img" alt="">
                                    </td>
                                    <td class="am-text-middle">{{ v.username }}</td>
                                    <td class="am-text-middle">{{ v.email }}</td>
                                    <td class="am-text-middle">{{ v.phone }}</td>
                                    <td class="am-text-middle">
                                        {% if v.sex == '0' %}
                                            女
                                        {% elif v.sex == '1' %}
                                            男
                                        {% endif %}  
                                    </td>
                                    <td class="am-text-middle">{{ v.age }}</td>

                                    <td class="am-text-middle isDelete">
                                        {% if v.isDelete %}
                                            已注销
                                        {% else %}
                                            正常
                                        {% endif %}

                                    </td>
                                    <td class="am-text-middle">{{ v.addtime|date:"Y-m-d H:i:s" }}</td>
                                    <td class="am-text-middle">
                                        <div class="tpl-table-black-operation">
                                            <a href="{% url 'myadmin_user_edit' v.id  %}">
                                                <i class="am-icon-pencil"></i> 编辑
                                            </a>
                                            <a href="javascript:;"  sid="{{ v.id }}"  class="tpl-table-black-operation-del">
                                                <i class="am-icon-trash"></i> 删除
                                            </a>
                                        </div>
                                    </td>
                                </tr>
                            {% endfor %}
                        
                                <!-- more data -->
                            </tbody>
                        </table>
                    </div>
                    <div class="am-u-lg-12 am-cf">
                        <div class="am-fr">
                            <ul class="am-pagination tpl-pagination">
                              

                            {% load pagetag %}
                           
                            {% showpage userlist.paginator.num_pages request %}
                                <!-- 这里用request,虽然可以用别的参数代替，但是热确实太在list别的地方要用到，就没有要重新定义一个变量 -->                   
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>


<script type="text/javascript">
    // 会员数据的删除

    // 给删除的按钮 绑定单击事件
    $('.tpl-table-black-operation-del').click(function(){
        // 获取id 否则删除谁
        var id = $(this).attr('sid')
        var btn = $(this)

        // 发送ajax请求， 执行数据的删除
        // ajax的请面2个数据-- '',{} 是给views的，function的参数才是views返回的,所以叫做回调函数
        $.get('{% url "myadmin_user_delete" %}', {id:id}, function(data){
            if(data['code']){
                // 在页面中 移除当前这条数据；如果没有没有接下来的命令，那么在views没有要求页面刷新的情况下，数据不刷新;ajax正是为了在页面不刷新的条件下获取数据
                btn.parents('tr').find('.isDelete').text('已注销')
            }
            alert(data['msg'])
        },'json')
    })
</script>

{% endblock %}